package API.PackagingClass.Integer;

import java.util.ArrayList;
import java.util.Scanner;

//此代码作用：重复输入处于(0,100]区间的数字，将其添加到ArrayList<Integer>容器中
//当容器中所有元素的和大于等于200时输出提示，并退出程序
public class AccumulateTo200ByArrayList {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        while(true){
            System.out.print("Enter an integer: ");
            int n = Integer.parseInt(sc.nextLine());
            if(n > 0 && n <= 100){
                list.add(n);
            } else {
                System.out.println("Invalid input");
                continue;
            }
            if(getSum(list) >= 200){
                System.out.println("Success");
                break;
            }
        }
    }
    public static int getSum(ArrayList<Integer> list){
        int sum = 0;
        for (Integer integer : list) {
            sum += integer;
        }
        return sum;
    }
}
